import bindBoxCard from "./bindBoxCard/index";
import unpackingGoods from "./unpackingGoods/index";
export default {
  data() {
    return {
      explainShow: false,
      unpackingShow: false,
      allDataList: {},
      inShow: false,
      activeIndex: 0
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    async getData() {
      let data = await $http.get("plugin.new-blind-box.frontend.index.index", {});
      if (data.result) {
        this.allDataList = data.data;
        this.activeIndex = this.$route.params.id ? this.allDataList.list.findIndex(item => item.id == this.$route.params.id) : 0
        this.inShow = true;
      } else {
        this.$toast(data.msg);
      }
    },
    // 说明
    clickExplain() {
      this.explainShow = true;
    },
    // 立即开箱
    clickUnpacking() {
      if(this.allDataList.list[this.activeIndex].show_status !== 1) {
        return
      }
      this.unpackingShow = true;
    },
    // 取消
    cancalEvent(value) {
      this.unpackingShow = false;
    },
    clickClose() {
      this.explainShow = false;
    },
    // 点击切换
    onTabClick(index) {
      this.activeIndex = index;
    },
    prevImg() {
      if(this.activeIndex <= 0) {
        this.activeIndex = 0;
        return
      }
      this.activeIndex = this.activeIndex - 1;
    },
    nextImg() {
      if(this.activeIndex >= this.allDataList.list.length - 1) {
        this.activeIndex = this.allDataList.list.length - 1;
        return
      }
      this.activeIndex = this.activeIndex + 1;
    }
  },
  components: { bindBoxCard, unpackingGoods }
};
